package com.ruoyi.system.service;

import com.ruoyi.system.service.impl.FmsMainServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 异步服务接口
 *
 * <p>提供各种财务数据的异步查询方法</p>
 *
 * @author ruoyi
 * @date 2024-08-18
 */
@Service
@Slf4j
public class IFutureService {

    /**
     * 异步获取月度财务数据
     *
     * @param fmsMainService FMS主服务
     * @param type 数据类型
     * @param threadPoolExecutor 线程池
     * @return CompletableFuture<BigDecimal> 月度财务数据
     */
    public CompletableFuture<BigDecimal> getFmsMainByTypeOfMonth(
            FmsMainServiceImpl fmsMainService,
            Integer type,
            ThreadPoolExecutor threadPoolExecutor) {
        return CompletableFuture.supplyAsync(
                () -> fmsMainService.selectFmsMainByTypeOfMonth(type),
                threadPoolExecutor
        );
    }

    /**
     * 异步获取周度财务数据
     *
     * @param fmsMainService FMS主服务
     * @param type 数据类型
     * @param threadPoolExecutor 线程池
     * @return CompletableFuture<BigDecimal> 周度财务数据
     */
    public CompletableFuture<BigDecimal> getFmsMainByTypeOfWeek(
            FmsMainServiceImpl fmsMainService,
            Integer type,
            ThreadPoolExecutor threadPoolExecutor) {
        return CompletableFuture.supplyAsync(
                () -> fmsMainService.selectFmsMainByTypeOfWeek(type),
                threadPoolExecutor
        );
    }

    /**
     * 异步获取财务数据
     *
     * @param fmsMainService FMS主服务
     * @param type 数据类型
     * @param threadPoolExecutor 线程池
     * @return CompletableFuture<BigDecimal> 财务数据
     */
    public CompletableFuture<BigDecimal> getFmsMainByTypeFuture(
            FmsMainServiceImpl fmsMainService,
            Integer type,
            ThreadPoolExecutor threadPoolExecutor) {
        return CompletableFuture.supplyAsync(
                () -> fmsMainService.selectFmsMainByType(type),
                threadPoolExecutor
        );
    }
}
